<template>
    <div class="banner">
        <img src="/static/login/qietu/beijing.png" width="100%" height="100%"/>
        <div class="danwei">
            <p style="color:white">绵阳市特种设备监督检验所</p>
            <p>1111</p>
        </div>
        <div class="banner1">
            <div class="login-form">
                <form method="post" action="" id="loginform">
                    <div class="yonghuming">
                        <input type="text" class="username" placeholder="请输入用户名" v-model="form.username"/>
                    </div>
                    <div class="mima">
                        <input type="password" class="username" placeholder="请输入密码"
                               v-model="form.password"/>
                    </div>
                    <div class="yanzhengma">
                        <input class="yanzheng" v-model="form.verifyCode"/>
                        <img src="/captcha" onclick="this.src='/captcha?'+Math.random()">
                    </div>
                    <div class="tijiao" @click="handleSubmit()">提交</div>
                </form>
            </div>
        </div>
    </div>
</template>
<script>
import Auth from "@/services/auth.js";

export default {
  data() {
    return {
      form: {
        username: '',
        password: '',
        verifyCode: ''
      }
    };
  },
  methods: {
    handleSubmit () {
      if (this.form.username.length === 0 || this.form.password.length === 0) {
        this.$Message.error('用户名或密码不能为空')
        return
      }
      let obj = this.form
      this.$http
        .post("index/login", obj, { emulateJSON: true, emulateHTTP: true })
        .then(
          res => {
            let data = res.data
            console.log(data)
            if (data && data.status === 1) {
              Auth.login(data.data.user)
              this.$router.push({ path: '/index/index' })
              this.$Message.success(data.msg)
            } else {
              this.$Message.error(data.msg)
            }
          },
          err => {
            this.$Message.error('请求错误')
          }
        );
    }
  }
}
</script>
<style scoped>
@import "../../../static/login/style.css";
</style>